/**
 * ...
 * @author Thot
 */

function ActionMenuScreen()
{
}


	//static
	ActionMenuScreen.ON_CLICK	= "onClick";
	ActionMenuScreen.ON_OPEN	= "onOpen";

	// private
	ActionMenuScreen.prototype._container	= null;
	
	// public
	ActionMenuScreen.prototype.signal		= null;
	
	ActionMenuScreen.prototype.init = function( p_container )
	{
		this.signal 		= new Signal();
		this._container 	= p_container;
		this.initMenu();
		this.initLayout();
	};
	
	ActionMenuScreen.prototype.initMenu = function()
	{
		this._container.addEventListener( "click", CallBack.create( this._clickHandler, this ) );
	};
	
	ActionMenuScreen.prototype.initLayout = function()
	{
		document.getElementById("openProjectButton").addEventListener( "click", CallBack.create( this._openProjectHandler, this ) );
	};
	
	ActionMenuScreen.prototype._openProjectHandler = function(event)
	{
		this._hideAllElements();
		var node 	= event.target;
		var url = document.getElementById("projectFilePath").value;
		this.signal.dispatchEvent( ActionMenuScreen.ON_OPEN, [url] ); 
	};
	
	ActionMenuScreen.prototype._clickHandler = function(event)
	{
		var node 	= event.target;
		var flag 	= node.id;
		var visible = event.type == "mouseover";
		
		this._hideAllElements();
		
		switch( flag )
		{
			case "file"		:this._setElementVisible("fileSub");			break;
			case "open"		:this._setElementVisible("openProjectLayout");	break;
			case "events"	:this._setElementVisible("eventSub");			break;
			case "database"	:this._setElementVisible("dbSub");				break;
			case "system"	:this._setElementVisible("sysSub");				break;
			case "help"		:this._setElementVisible("helpSub");			break;
			
			default: 
				this.signal.dispatchEvent( ActionMenuScreen.ON_CLICK, [flag] ); 
				break;
		}
	};
	
	ActionMenuScreen.prototype._hideAllElements = function()
	{
		var elements = ["fileSub","eventSub","dbSub","sysSub","helpSub","openProjectLayout"];
		var i = 0;
		var max = elements.length;
		
		for( i = 0; i < max; i++ )
		{
			document.getElementById(elements[i]).style.display = "none";
		}
	};
	
	ActionMenuScreen.prototype._setElementVisible = function( p_id )
	{
		var element = document.getElementById(p_id);
		
		if( !element.style )
		{
			element.setAttribute("style","");
		}
		
		//var visible = ( element.style.display != "block" );
		//element.style.display = ( visible ) ? "block" : "none";
		element.style.display = "block";
	};


	
